<template>
    <div id="app" >
        <el-button type="text">阅读{{ timeLeft}}秒可关闭</el-button>
    </div>

</template>
<script>
export default {
  name: 'CountDown',
  props: {
    time: {
      type: Number,
      default: 20
    }
  },
  data() {
    return {
      t: '',
      flag: false,
      timeLeft: 20
    }
  },
  mounted: function() {
    this.timeLeft = this.time
    const t = setInterval(() => {
      if (this.flag === true) {
        clearInterval(t)
      }
      this.countdown()
    }, 1000)
  },
  methods: {
    countdown: function() {
      this.timeLeft = this.timeLeft - 1
      if (this.timeLeft <= 1) {
        this.flag = true
        this.$emit('getChildrenNotify', this.timeLeft)
      }
    }
  }
}
</script>